<?php
// +----------------------------------------------------------------------
// | Jqcms [ Avenue to Jane ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://jqcms.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: hyacinth <845077398@qq.com>
// +----------------------------------------------------------------------
namespace Admin\Model;
use Think\Model;
class PageModel extends Model{
    
    protected $_validate =array(
      
        array('title','require','标题不能为空!'),
        array('alias','require','别名不能为空!'),
        array('content','require','内容不能为空!'),
    );
    
    protected $_auto=array(
        array('dateline','time',3,'function'),
        array('keywords','setKeywords',3,'callback'),
        array('desc','setDesc',3,'callback'),
        
    );
    
    public function setKeywords(){
    
        $keywords = preg_replace("/(\n)|(\s)|(\t)|(\')|(')|(，)/",',',I('keywords'));
        $keywords = explode(',', $keywords);
        $keywords = array_filter($keywords);
        $keywords = array_unique($keywords);
        $keywords = implode(',', $keywords);
        return $keywords;
    
    }
    
    public function setDesc(){
    
        if(I('desc')!=null){
            return I('desc');
        }else {
            $content =htmlspecialchars_decode(I('content'));
            $content = strip_tags($content);
            $content = substr($content, 0,200);
            return $content;
        }
    
    }
    
    public function dateline(){
        
        $dateline = strtotime($_POST['dateline']);
            
        return $dateline;
        
    }
    
    
     
  
    
}